@extends('admin.formLayout')
@if(isset($id))
    @section('title','编辑栏目')
@section('barName','编辑栏目')
@else
    @section('title','添加栏目')
@section('barName','添加栏目')
@endif
@section('content')
    <form class="layui-form" @if(!isset($id)) action="{{route('admin.category-add')}}" @else action="{{route('admin.category-edit',['id'=>$id])}}" @endif method="post">
        <div class="layui-tab" lay-filter="posts">
            <ul class="layui-tab-title">
                <li class="layui-this">常规选项</li>
                <li class="">高级选项</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-row">
                            <div class="layui-col-md12">
                                {{csrf_field()}}
                                @if(isset($id))
                                    <input type="hidden" name="id" value="{{$id}}">
                                @endif
                                <div class="layui-form-item">
                                    <label class="layui-form-label">状态</label>
                                    <div class="layui-input-block">
                                        @foreach($status as $k=>$v)
                                            <input type="radio" name="status" value="{{$k}}" title="{{$v}}" @if(old('status')) {{$k==old('status')?'checked':''}} @else @if(isset($model->status) && $k==$model->status) checked @endif @endif />
                                        @endforeach
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">栏目名称<span style="color:red">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="cat_name" lay-verify="required"  value="@if(old('cat_name')){{old('cat_name')}}@else{{$model->cat_name or ''}}@endif" autocomplete="off" placeholder="请输入栏目名称" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">排序</label>
                                    <div class="layui-input-block">
                                        <input type="number" name="sort" value="@if(old('sort')){{old('sort')}}@else{{$model->sort or ''}}@endif"  class="layui-input" style="width: 50px" min="1" step="1">
                                        (低->高)
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">唯一标识<span style="color:red">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="slug"   value="@if(old('slug')){{old('slug')}}@else{{$model->slug or ''}}@endif" autocomplete="off" placeholder="请确保标识的唯一性标识仅支持英文字符不区分大小写" class="layui-input" lay-verify="required" >
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">上级栏目<span style="color:red">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="pid" lay-verify="required">
                                            <option value="0">顶级栏目</option>
                                            {!! $categories !!}}
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">内容属性</label>
                                    <div class="layui-input-block">
                                        <select name="ispart">
                                            @foreach(\App\Service\Category::getCatAttr() as $k=>$v)
                                                <option value="{{$k}}" @if(old('ispart')){{old('ispart')==$k?'selected':''}}@elseif(isset($model->ispart)){{$model->ispart==$k?'selected':''}}@endif>{{$v}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">栏目交叉</label>
                                    <div class="layui-input-block">
                                            @foreach(\App\Service\Category::getCatCross() as $k=>$v)
                                                <input type="radio" name="cross" value="{{$k}}" title="{{$v}}" lay-filter="cross" @if(old('cross')){{old('cross')==$k?'checked':''}}@elseif(isset($model->cross)){{$model->cross==$k?'checked':''}}@endif />
                                            @endforeach
                                    </div>
                                </div>
                                <div class="layui-form-item" id="crossid">
                                    <label class="layui-form-label">交叉栏目</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="crossid"   value="@if(old('crossid')){{old('crossid')}}@else{{$model->crossid or ''}}@endif" autocomplete="off" placeholder="手工指定栏目逗号分开" class="layui-input"  onkeyup="this.value=this.value.replace(/[^\d^\,^\-]/,'')" >
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit="" lay-filter="form">立即提交</button>
                                        <button type="button"  onclick="javascript:location.href='{{route('admin.category')}}'" class="layui-btn layui-btn-primary">返回</button>
                                    </div>
                                </div>
                    </div>
                </div>

            </div>
                <div class="layui-tab-item">
                    <div class="layui-row">
                        <div class="layui-col-md12">
                            {{csrf_field()}}
                            @if(isset($id))
                                <input type="hidden" name="id" value="{{$id}}">
                            @endif
                            <div class="layui-form-item">
                                <label class="layui-form-label">关键字（用于SEO）</label>
                                <div class="layui-input-block">
                                    <input type="text" name="keywords"  value="@if(old('keywords')){{old('keywords')}}@else{{$model->keywords or ''}}@endif" autocomplete="off" placeholder="用于列表页SEO优化" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">描述（用于SEO）</label>
                                <div class="layui-input-block">
                                    <input type="text" name="desc" value="@if(old('desc')){{old('desc')}}@else{{$model->desc or ''}}@endif"  class="layui-input" placeholder="用于列表页SEO优化">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">封面模板</label>
                                <div class="layui-input-block">
                                    <select name="tempindex">
                                        <option value=" ">请选择模板</option>
                                        @foreach($templatesChannel as $k=>$v)
                                            <option value="{{$k}}" @if(old('tempindex')) {{old('tempindex')==$k?'selected':''}} @else @if(isset($model->tempindex)&&$model->tempindex==$k) selected @endif @endif>{{$v}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">列表模板</label>
                                <div class="layui-input-block">
                                    <select name="templist">
                                        <option value=" ">请选择模板</option>
                                        @foreach($templatesList as $k=>$v)
                                            <option value="{{$k}}" @if(old('templist')) {{old('templist')==$k?'selected':''}} @else @if(isset($model->templist)&&$model->templist==$k) selected @endif @endif>{{$v}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">文章模板</label>
                                <div class="layui-input-block">
                                    <select name="temparticle">
                                        <option value=" ">请选择模板</option>
                                        @foreach($templatesArticle as $k=>$v)
                                            <option value="{{$k}}" @if(old('temparticle')) {{old('temparticle')==$k?'selected':''}} @else @if(isset($model->temparticle)&&$model->temparticle==$k) selected @endif @endif>{{$v}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="form">立即提交</button>
                                <button type="button"  onclick="javascript:location.href='{{route('admin.category')}}'" class="layui-btn layui-btn-primary">返回</button>
                            </div>
                        </div>
                    </div>
                </div>

            </div>

    </form>
@endsection
@section('script')

    <script>
        layui.use(['element','form','layer','upload','jquery'], function(){
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;
            var upload = layui.upload;
            var $ = layui.jquery;
            if($('[name=cross]').val()==2){
                $('#crossid').show();
            }else{
                $('#crossid').hide();
            }
            form.on('submit(*)',function(data){
                console.log(data);
                return false;
            });
            //一些事件监听
            element.on('tab(posts)', function(data){
            });
            form.on('radio(cross)', function(data){
                //console.log(data.elem); //得到checkbox原始DOM对象
//                console.log(data.elem.checked); //是否被选中，true或者false
//                console.log(data.value); //复选框value值，也可以通过data.elem.value得到
                var value   =  data.value;
                var checked = data.elem.checked;
                if(value==2&&checked){
                    $('#crossid').show()
                }else{

                    $('#crossid').hide();
                }
                //console.log(data.othis); //得到美化后的DOM对象
            });
            @if (count($errors) > 0)
                @foreach ($errors->all() as $error)
                    layer.msg('{{$error}}',{'icon':2});
                    @break
                @endforeach
            @endif

        });
    </script>
@endsection